package com.fenshi.interactor.imp;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.android.volley.Request;
import com.android.volley.VolleyError;
import com.fenshi.bean.RequestBean;
import com.fenshi.interactor.LockOrUnLockInteractor;
import com.fenshi.presenter.listener.RequestListener;
import com.fenshi.until.MethodCode;
import com.fenshi.until.MethodType;
import com.quickdv.helper.NetWorkImp;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lilongfei on 15/10/11.
 */
public class LockOrUnLockInteractorImp extends NetWorkImp implements LockOrUnLockInteractor {

    RequestListener<JSONObject> listener;


    public LockOrUnLockInteractorImp(Context c) {
        super(c);
    }

    public LockOrUnLockInteractorImp(Context c,RequestListener<JSONObject> listener){
        super(c);
        this.listener = listener;
    }

    @Override
    public void unLockOrLock(String userId, String carId, String type) {
        RequestBean bean = new RequestBean();
        Map<String,Object> params = new HashMap<>();
        params.put("carId",carId);
        params.put("type", type);
        bean.setRequestParams(params);
        bean.setUserSession(userId);
        bean.setRequestCode(MethodType.MANAGER_ORDER_LIST);
        addFastJsonQueue(Request.Method.POST, MethodType.MANAGER_ORDER_LIST, (JSONObject) JSON.toJSON(bean));
        startRequest();
    }

    @Override
    public void backOrder(String userId, String orderId) {

    }

    @Override
    protected void onRequestSuccess(Object tag, JSONObject result) {
        JSONObject response = result.getJSONObject(MethodCode.responseContent_key);
        int statue = response.getInteger(MethodCode.responseStatue);

        if (statue == (MethodCode.NetState.SUCCESS.getValue())) {

            if (tag.toString().equals(MethodType.LOGIN)) {

                listener.Success(tag + "", response);
            } else
                listener.Error(tag + "", "用户名密码错误");
        }
    }

    @Override
    protected void onRequestExcption(VolleyError error) {
        listener.Exception("", error);
    }
}
